package system

import (
	"MoSkeleton/framework/core/dto/response"
	"MoSkeleton/models/system"
	s1 "MoSkeleton/web/pogos/request/system"
	"github.com/gin-gonic/gin"
	"strconv"
)

type RoleAuthUserService struct {
}

func (s *RoleAuthUserService) GetAllocatedListPage(c *gin.Context, userItem *s1.RoleAllocatedUserItemReq) (*response.PageResult, error) {
	return sysUserService.GetAllocatedListPage(c, userItem)
}

func (s *RoleAuthUserService) GetUnallocatedListPage(c *gin.Context, userItem *s1.RoleAllocatedUserItemReq) (*response.PageResult, error) {
	return sysUserService.GetUnallocatedListPage(c, userItem)
}

func (s *RoleAuthUserService) AuthUserAll(c *gin.Context, authUserAllReq *s1.SysRoleAuthUsersReq) (int64, error) {
	//DONE 校验角色是否有数据权限
	if err := sysRoleService.CheckRoleDataScope(c, authUserAllReq.ID); err != nil {
		return 0, err
	}
	return new(system.SysUserRole).AddRoleUserIds(nil, authUserAllReq.ID, authUserAllReq.UserIds)
}

func (s *RoleAuthUserService) CancelAuthUser(roleAuthUser *s1.SysRoleAuthUserReq) (bool, error) {
	userId, _ := strconv.ParseUint(roleAuthUser.UserId, 10, 64)
	return new(system.SysUserRole).Delete(nil, userId, roleAuthUser.ID)
}

func (s *RoleAuthUserService) CancelAuthUsers(roleAuthUsers *s1.SysRoleAuthUsersReq) (bool, error) {
	return new(system.SysUserRole).DeleteByRoleUserIds(nil, roleAuthUsers.ID, roleAuthUsers.UserIds)
}
